package com.open.party.cloud.view.mine

import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentPagerAdapter
import cn.android.x.parent.AppTitleBaseActivity
import com.gyf.immersionbar.ImmersionBar
import com.open.party.cloud.R
import com.open.party.cloud.view.MineMainFragment
import kotlinx.android.synthetic.main.title_tab_view_page_for_mine.*

class MineMainActivity : AppTitleBaseActivity() {

    private var index = 0

    override fun getLayoutResId(): Int = R.layout.title_tab_view_page_for_mine

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setViewTitle("我的")
        ImmersionBar.with(this@MineMainActivity)
            .statusBarDarkFont(false).init()
        initTabView()
    }

    override fun setViewTitle(centerTxt: String?) {
        titleBarView = findViewById(R.id.titleBarView)
        titleBarView.setLeftIcon(R.drawable.icon_back_white)
        titleBarView.setLeftVisible(View.VISIBLE)
        titleBarView.setLeftViewClickListener { finish() }
        titleBarView.setCenterTxt(centerTxt)
        titleBarView.setCenterTxtColor(R.color.white)
    }

    private fun initTabView() {
        val titleList = ArrayList<String>()
        val typeList = ArrayList<String>()

        titleList.add("我的")
        typeList.add("")

        initTab(
            titleList,
            getFragments(typeList)
        )
    }

    private fun getFragments(typeList: java.util.ArrayList<String>): List<Fragment> {
        val fragments: ArrayList<Fragment> = ArrayList()
        val fragment = MineMainFragment()
        fragments.add(fragment)

//        for (type in typeList) {
//            val fragment = ArticleListFragment()
//            val bundle = Bundle()
//            bundle.putString("type", type)
//            fragment.arguments = bundle
//            fragments.add(fragment)
//
//            Log.e("type", type)
//        }

        return fragments
    }

    private fun initTab(titles: ArrayList<String>, fragments: List<Fragment>) {

        val fragmentPagerAdapter = object : FragmentPagerAdapter(supportFragmentManager, FragmentPagerAdapter.BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
            override fun getCount(): Int {
                return fragments.size
            }

            override fun getItem(arg0: Int): Fragment {
                return fragments[arg0]
            }
        }

//        if (itemList!!.size == 1) {
//            scrollTabView.visibility = View.GONE
//        } else {
//            scrollTabView.visibility = View.VISIBLE
//        }
//        scrollTabView.visibility = View.GONE
        viewPager.offscreenPageLimit = titles.size - 1
        viewPager.adapter = fragmentPagerAdapter
        //        pager.addOnPageChangeListener(this);

//        scrollTab.setTitles(titles, index, titles.size <= 4)
////        scrollTab.setNumber(1, "9", View.VISIBLE)//设置数字红点
//        scrollTab.setViewPager(viewPager)
//        scrollTab.setOnTabListener { index, _ ->
//            viewPager.setCurrentItem(index, true)
//        }
    }
}